window.mofang.moniter.proxyIpBill = function() {

	var params = {data:{page : 1, pageSize : 10}, url : 'monitor/ProxyIpStatistics/obtainProxyIp.koala'};
	var paramsProxyIp = {data:{page : 1, pageSize : 10}, url : 'monitor/ProxyIpStatistics/obtainProxyIpGroupByChannel.koala'};
	
	var init = function() {
		// 任务显示init
		_grid.init();
		pageTool.init();
		requestData();
	};
	
	var pageTool = page({
	renderTo : "proxy_ip_bill_Page",
	pageSize : params.data.pageSize,
	subHandler : function(data) {
		params.data.page = data.currNo;
		params.data.pageSize = data.pageSize;
		requestData();
	}
	});
	
	var _grid = grid({
	renderTo 	: 'proxy_ip_bill_grid', 
	columns  : [	{name : '代理IP', dataIndex : 'ip'},
	             	{name : '成功次数', funHandler: function(data){
	             			var value = data.successNumber;
	             			if(value == null || value == 'null' || value == ''){
	                    		return '0';
	                    	} else {
	                    		return value;
	                    	}
	             		}
	             	},
	             	{name : '失败次数',funHandler: function(data){
	             			var value = data.failNumber;
	             			if(value == null || value == 'null' || value == ''){
	                    		return '0';
	                    	} else {
	                    		return value;
	                    	}
	             		}
	             	},
	             	{name : '成功率', funHandler: function(data){
		             		var rates = data.successRate;
		             		if(rates >= 90){
		             			return '<font color="green">' + rates + '%</font>';
		             		} else if(rates < 70){
		             			return '<font color="red">' + rates + '%</font>';
		             		} else {
		             			return '<font color="green">' + rates + '%</font>';	
		             		}
	             		}
	             	},
	             	{name : '分渠道统计',renderer : function(data) {
			            	var hrefHtml = '<a id="g_detail">统计信息</a>&nbsp;';
			            	return hrefHtml;
						},
						rendererCall : function(obj) {
							var command = {
								"g_detail" : function(data){requestDataByProxyIp(data);},
								};
//							console.log(obj.id + "    " + obj.data);
							command[obj.id](obj.data);
						}
					}
	           ]
	});
	
//	var viewDetail = function(data){
//		var dealData = requestDataByProxyIp(data);
//		console.log(dealData);
//		new webBox({
//			title 			: '分渠道代理IP信息统计',
//			url   			: 'pages/monitor/task-bill.jsp',
//			btn     		: false,
//			width			: 650,
//			templateRender	: dealData
//		}).init().show();
//	};
	
	var requestData = function(data) {
		util.mofangAjax({
			url       : params.url,
			data      : params.data ,
			succFun   : function(json) {
				_grid.addDatas({
					rowDatas : json.Rows
				});
				pageTool.render(json.Total, params.data.page);
			}
		
		});
	};
	
	var requestDataByProxyIp = function(row){
		console.log(row.ip);
		paramsProxyIp = $.extend(true, {}, paramsProxyIp, {data:{ip : row.ip}});
		console.log(paramsProxyIp);
		util.mofangAjax({
			url       : paramsProxyIp.url,
			data      : paramsProxyIp.data ,
			succFun   : function(json) {
				new webBox({
					title 			: '分渠道代理IP信息统计',
					url   			: 'pages/monitor/monitor-proxy-ip-view.jsp',
					btn     		: false,
					width			: 650,
					templateRender	: json
				}).init().show();
			}
		});
	};
	
	
	return {
	init : init
	};
};